﻿using DXApplicationTangche.service;
using DXApplicationTangche.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.DTO
{
    public class 面料图片Dto
    {
        public String materialid { get; set; }
        public String materialcd { get; set; }
        public String materialname { get; set; }
        public Image Picture { get; set; }
        public 面料图片Dto (DataRow dr)
        {
            this.materialid = dr["id"].ToString();
            this.materialcd = dr["materialCode"].ToString();
            this.materialname = dr["mianliao"].ToString();
            try
            {
                this.Picture = Image.FromFile(@"pic\" + dr["picn"].ToString());
            }
            catch
            {
                this.Picture = DXApplicationTangche.Properties.Resources.SSHIRT;
            }
        }
    }

    public class 面料样品DTO {
        public String ORDER_ID { get; set; }    //  订单id
        public String MATERIAL_ID { get; set; } //  面料id
        public String UNIT_CONSUMPTION { get; set; }    //  单耗
        public Image SAMPLE_PIC { get; set; }   //  图片
        public String imageIOStream { get; set; }   //  图片IO流
        public String REMARK { get; set; }  //  备注

        /// <summary>
        /// 数据库中取数据
        /// </summary>
        /// <param name="dataRow"></param>
        public 面料样品DTO(DataRow dataRow) {
            this.ORDER_ID = dataRow["ORDER_ID"].ToString();
            this.MATERIAL_ID = dataRow["MATERIAL_ID"].ToString();
            this.UNIT_CONSUMPTION = dataRow["UNIT_CONSUMPTION"].ToString();
            this.SAMPLE_PIC = FileService.convertToImage(dataRow["SAMPLE_PIC"].ToString()); ;
            this.REMARK = dataRow["REMARK"].ToString();
        }
        public 面料样品DTO()
        {
            this.ORDER_ID = "";
            this.MATERIAL_ID = "";
            this.UNIT_CONSUMPTION = "";
            this.SAMPLE_PIC = null;
            this.REMARK = "";
        }
        /// <summary>
        /// 插入数据库
        /// </summary>
        /// <param name="ORDER_ID"></param>
        /// <param name="MATERIAL_ID"></param>
        /// <param name="UNIT_CONSUMPTION"></param>
        /// <param name="SAMPLE_PIC"></param>
        /// <param name="REMARK"></param>
        public 面料样品DTO(String ORDER_ID,String MATERIAL_ID,String UNIT_CONSUMPTION, ImageUtil imageUtil, String REMARK) 
        {
            this.ORDER_ID = ORDER_ID;
            this.MATERIAL_ID = MATERIAL_ID;
            this.UNIT_CONSUMPTION = UNIT_CONSUMPTION;
            this.imageIOStream = imageUtil.fileIOStream;
            this.REMARK = REMARK;
        }
    }
}
